<?php 
//------------------------------------------------------------------------------------------//
//--                                         P H P                                        --// 
//------------------------------------------------------------------------------------------//
$title='Dashboard'; //Page Title
//---> Include
require_once("header.php");
include('MenuNav.php');

$tip_msg = 'To sort multiple column, sort the first column in descending or ascending order then hold the shift key and click the second column you wish to sort(if successful the 2 column will be highligted)';
?>
		
	<section id="content"> 
<?php
if( !empty($_SESSION['msg']) ){
	echo $_SESSION['msg'];
	unset($_SESSION['msg']);
}else{}

if($_SESSION['level'] >= 1)	{

//ADMIN's Dashboard
if(file_exists('DashboardAdmin.php'))	
	include 'DashboardAdmin.php';
	
}else{

//get client term and condition status (0 means not yet showed)
$client_id = $_SESSION['user_id'];
$row_termsStat = mysql_fetch_array(mysql_query("SELECT termsStat FROM clients WHERE cusid='$client_id'"));
$termsStat = $row_termsStat['termsStat'];
if($termsStat == 0){
echo "<script type=\"text/javascript\">

alert(unescape('TERMS AND CONDITIONS%0A%0ACOPYRIGHT%0AThis site is the property of Lay Bare Waxing Philippines, Inc. You may not modify, alter, copy, download, re-publish, re-display, transfer, or distribute in any manner whatsoever any content found in this site. However, you may download any of the content herein for purely personal purposes only.%0A%0AAUTHORITY TO PUBLISH%0AAny message you publish in the site gives Lay Bare Waxing Philippines, Inc. the authority, without any compensation, to copy, use, display, or transmit the information contained therein to the public.%0A%0APRIVACY%0ALay Bare Waxing Philippines, Inc. undertakes to respect the privacy of users and shall maintain the confidentiality of your email address and private messages%0A%0ANO WARRANTIES%0AWhile Lay Bare Waxing Philippines, Inc. makes diligent effort to protect the confidentiality and privacy of users, it does not guarantee full protection thereof; hence, cannot be held liable for damages sustained by any party arising out of or in connection with the use of the website.'));
</script>";

//user_record
$sql_updt = "UPDATE clients SET termsStat='1'  WHERE cusid='$client_id'";

if(!mysql_query($sql_updt,$con)) 
{
die('Error:'.mysql_error());
}
}
						
//CLIENT's Dashboard
if(file_exists('DashboardClient.php'))	
	include 'DashboardClient.php';
	
}
?>

<!-----------------  ---------------->

<!--- END of  --->

	</section>
	<?php
	//phpinfo();
	?>
	<?php include('footer.php') ?>
<?php
	$currentdate= date('Y-m-d');
	
	//get all expired today
	$sql_expired = mysql_query("SELECT * FROM appointments WHERE status='reserved' AND app_reserved<'$currentdate' ");
	while($row_exp = mysql_fetch_array($sql_expired)){
	$reserve_id = $row_exp['reserve_id'];
	$app_reserved = $row_exp['app_reserved'];
	$app_reserved2 = date('Y-m-d', strtotime($app_reserved. ' + 1 day'));
	
	$daily_expired_ct = $daily_expired_ct + 1;
	$branch_id = $row_exp['branch'];
	$date_reserved = $row_exp['date_reserved'];
	$cus_id = $row_exp['cusid'];
	$start_time=$row_exp['start_time'];
	$end_time=$row_exp['end_time'];
	$apptime=date("g:i", strtotime($start_time)).'-'.date("g:i a", strtotime($end_time)); 
	$initiated_by=$row_exp['initiated_by'];
	$clname=$row_exp['clname'];
	
	//get technician
	$technician = $row_exp['technician'];
	$sql_tech=mysql_query("SELECT techname FROM technician WHERE techid='{$technician}'");
	$rowtech=mysql_fetch_assoc($sql_tech);
	$techname=$rowtech['techname'];
	
	//get service
	$service = $row_exp['service_id'];
	$sql_serv=mysql_query("SELECT service_name FROM services WHERE service_id='{$service}'");
	$rowserv=mysql_fetch_assoc($sql_serv);
	$servicename=$rowserv['service_name'];
	
	$sql_cl=mysql_query("Select cusemail, cusmob from clients WHERE cusid = '{$cus_id}'");
	$row_cl=mysql_fetch_assoc($sql_cl);
	$cusemail=$row_cl['cusemail'];
	$cusmob=$row_cl['cusmob'];
		
	include 'mailExpired.php';
	
	//echo "<script type=\"text/javascript\">console.log('$branchemail')</script>";	
	}
	
	$sql="UPDATE appointments SET status='expired' WHERE status='reserved' AND app_reserved<'$currentdate'";
	
	if(!mysql_query($sql,$con)) {
		die('Error:'.mysql_error());
	}else{
		echo "<script type=\"text/javascript\">console.log('expired status updated!!!')</script>";	
	}
	/*/fetch all appointment & compare date if expired
	$msq_appoint = mysql_query("SELECT * FROM appointments WHERE status='expired' AND branch IN (".$adminbrreg.")");
	while($row_exp = mysql_fetch_array($msq_appoint)){
	$app_reserved = $row_exp['app_reserved'];
	$app_reserved2 = date('Y-m-d', strtotime($app_reserved. ' + 1 day'));
	
		if($app_reserved2 == $currentdate){
		echo  $app_reserved2."-".$row_exp['branch']."<br />";
		}
	}
	echo $adminbrreg;
	//echo $app_reserved . "=". $app_reserved2 . "=". $currentdate;
	*/
?>
</body> 
</html>
